package string.nowcoder.easy;

import java.util.Scanner;

/**
 * @author bruin_du
 * @description 树根
 * https://www.nowcoder.com/questionTerminal/e2422543519249f292d8435394ab82fe
 * @date 2022/5/23 17:00
 **/
public class TreeRoot {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String str = in.next();
            while(str.length() > 1) {
                int sum = 0;
                for (int i = 0; i < str.length(); i++) {
                    sum += str.charAt(i) - '0';
                }
                str = String.valueOf(sum);
            }
            System.out.println(str);
        }
    }
}
